package com.gzyct.m.api.common.sign;

import java.util.HashMap;
import java.util.Map;

import com.gzyct.m.api.common.intf.req.InterfaceRequest;
import com.gzyct.m.api.common.intf.req.ProtocolType;
import com.gzyct.m.api.common.intf.resp.InterfaceResp;

public class SignStringBuildWorker {

	private static Map<ProtocolType, SignStringBuilder> map = new HashMap<ProtocolType, SignStringBuilder>();

	static {
		map.put(ProtocolType.HTTP_PARAM, new HttpParamSignStringBuilder());
		map.put(ProtocolType.HTTP_JSON, new HttpJsonSignStringBuilder());
	}

	public static String requestBuild(InterfaceRequest ir) {
		SignStringBuilder ssb = map.get(ir.getProtocolType());
		if (ssb == null) {
			throw new RuntimeException("No sign string builder found for type " + ir.getProtocolType());
		} else {
			return ssb.requestBuild(ir);
		}
	}

	public static String respBuild(InterfaceResp ir) {
		SignStringBuilder ssb = map.get(ir.getProtocolType());
		if (ssb == null) {
			throw new RuntimeException("No sign string builder found for type " + ir.getProtocolType());
		} else {
			return ssb.respBuild(ir);
		}
	}

	public static InterfaceResp updateSign(InterfaceResp ir, String sign) {
		SignStringBuilder ssb = map.get(ir.getProtocolType());
		if (ssb == null) {
			throw new RuntimeException("No sign string builder found for type " + ir.getProtocolType());
		} else {
			return ssb.updateSign(ir, sign);
		}
	}

}
